package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.ProductInfoProjectMapperExt;
import com.lzy.product.dtos.ProductInfoProjectDto;
import com.lzy.product.entity.ProductInfoProject;
import com.lzy.product.service.ProductInfoProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2017/12/1.
 */
@Service
public class ProductInfoProjectServiceImpl implements ProductInfoProjectService {
    @Autowired
    ProductInfoProjectMapperExt productInfoProjectMapperExt;

    @Override
    public Long insert(ProductInfoProjectDto dto) {
        return productInfoProjectMapperExt.insertSelective(DozerUtils.map(dto, ProductInfoProject.class)) > 0 ? 1L : null;
    }

    @Override
    public Boolean update(ProductInfoProjectDto dto) {
        return productInfoProjectMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, ProductInfoProject.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return null;
    }

    @Override
    public Boolean remove(Long id) {
        return null;
    }

    @Override
    public ProductInfoProjectDto findById(Long id) {
        return null;
    }

    @Override
    public List<ProductInfoProjectDto> query(ProductInfoProjectDto dto) {
        return productInfoProjectMapperExt.query(dto);
    }

    @Override
    public PageInfo<ProductInfoProjectDto> selectList(Pager pager, ProductInfoProjectDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ProductInfoProjectDto> productInfoProjectDtoList = productInfoProjectMapperExt.query(dto);
        return new PageInfo<>(productInfoProjectDtoList);
    }

    @Override
    public Integer deleteByProductId(ProductInfoProjectDto dto) {
        return productInfoProjectMapperExt.deleteByProductId(dto);
    }

    @Override
    public ProductInfoProjectDto findByProductIdAndProjectId(Long productId, Long projectId) {
        return productInfoProjectMapperExt.findByProductIdAndProjectId(productId,projectId);
    }

    @Override
    public List<ProductInfoProjectDto> findByProductId(Long productId) {
        return productInfoProjectMapperExt.findByProductId(productId);
    }

}
